package logic

import (
	"context"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodListLogic) GoodList(in *srv.GoodListRequest) (*srv.GoodListResponse, error) {
	// todo: add your logic here and delete this line

	var good []mysql.Good
	mysql.DB.Where("good_adopt = ?", in.GoodAdopt).Find(&good)
	var lists []*srv.GoodList
	for _, m := range good {
		list := srv.GoodList{
			GoodId:    int64(m.ID),
			GoodName:  m.GoodName,
			GoodNum:   m.GoodNum,
			GoodPrice: float32(m.GoodPrice),
			GoodLike:  m.GoodLike,
			GoodAdopt: int64(m.GoodAdopt),
		}
		lists = append(lists, &list)
	}

	return &srv.GoodListResponse{
		List: lists,
	}, nil
}
